<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/static/js/jquery-3.4.1.js"></script>
</head>
<body>
<table border="1">
    <thead>
    <tr>
        <th>序号</th>
        <th>物资编号</th>
        <th>物资名称</th>
        <th>购买时间</th>
        <th>所属实验室</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {% for foo in material_all %}
        <tr>
            <td>{{ forloop.counter }}</td>
            <td>{{ foo.mater_num }}</td>
            <td>{{ foo.material_name }}</td>
            <td>{{ foo.buy_time }}</td>
            <td>{{ foo.l_id__l_name }}</td>
            <td>
                <button class="del" url="/material_del/?id={{ foo.id }}">删除</button>
                <button><a href="/material_alter/?id={{ foo.id }}">修改</a></button>
            </td>
        </tr>
    {% endfor %}
    </tbody>
</table>
<a href="/material_add/">添加</a>
<script src="/static/js/sweetalert.min.js"></script>

<script>
    $('.del').click(function () {
        var _this = $(this);
        swal({
            title: "确认删除?",
            text: "一旦删除，文件将无法恢复!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        }).then((willDelete) => {
            if (willDelete) {

                $.ajax({
                    url: _this.attr('url'),
                    type: 'get',
                    success: (res) => {
                        if (res.status === 200) {

                            swal("文件已被删除!", {
                                icon: "success",
                            });
                            _this.parent().parent().remove()
                        } else {
                            swal("文件未删除!");
                        }
                    }
                })
            } else {
                swal("文件未删除!");
            }
        });
    });
</script>
</body>
</html>





